/**
 * 找游戏初始化banner
 * Created by 小黑 on 2017/10/19.
 */
(function () {
    function main() {
        createSwiper();

        //必须使用data.attr
        var template =
            `<li class="common-game-item">
            <a class="common-game-avatar" href="/game/detail/{% data.id %}" target="_blank">
                <img data-original="{% data.img %}">
            </a>
            <div class="common-game-detail">
              <div class="common-game-info">
                <div class="common-game-name">
                  <a class="ellipse" href="/game/detail/{% data.id %}" target="_blank">{% data.name %}</a>
                  {% if( data.is_android ){ %}
                    <span class="iconfont icon-anzhuo"></span>
                  {% } %}
                  {% if( data.is_ios ){ %}
                    <span class="iconfont icon-iOS"></span>
                  {% } %}
                </div>
                <div class="common-game-intro ellipse">
                    <div class="common-game-describe">类型： <span>{% data.cate_id %}</span></div>
                    <div class="common-game-describe"><span>{% data.nums %}</span>人关注</div></div>
                <div class="common-game-additional common-game-tags">
                     {% for(var i = 0; i < data.tags.length; i++ ) { %}
                        <span> {% data.tags[i] %} </span>
                     {% } %}
                </div>
              </div>
            </div>
        </li>`;

        //创建点击加载更多功能
        var loadGameList = new LoadData({
            btn: '#getMoreBtn',
            lists: '#gameTotalList',
            listType: 'game',
            url: '/game/ajax_game_list/',
            page: 2,
            template: template,
            method: 'append',
            loadingAnim: true,
            loadingAnimDom: '.loading-container',
            handleFn: {
                'cate_id': utils.setDataItem.bind(utils),
                'tags': utils.setDataItem.bind(utils)
            },
            afterRender: function () {
                $("img").lazyload({
                    effect: "fadeIn",
                    effectspeed: 1500
                });
            }
        });
    }
    // 创建banner Swiper
    function createSwiper(){
        var findGameBanner = new Swiper('.find-game-banner', {
            slidesPerView: 'auto',
            spaceBetween: 10,
            nextButton: '.swiper-button-next',
            loop: true,
            loopedSlides: 2,
            onSlideChangeEnd: function( swiper ){
                $("img").lazyload({
                    effect: "fadeIn",
                    effectspeed: 1500
                });
            }
        });
    }
    main();
})();